package structure_结构性.flyweight_pattern_享元模式;

import java.util.concurrent.ConcurrentHashMap;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: hihi
 * @Date: 2020/07/07/14:13
 * @Description:
 */
public class ShapeFactory {

	private static final ConcurrentHashMap<String, Shape> cache = new ConcurrentHashMap<>();

	public static Shape getShape(String color) {
		Shape shape = cache.get(color);
		if (shape == null) {
			shape = new Circle(color);
			cache.put(color, shape);
		}
		return shape;
	}
}
